/*
 * NestedSM.c
 *
 *  Created on: Oct 29, 2012
 *      Author: banfield
 */

/*****************************************************
 * Include Statements
 ****************************************************/
#include "NestedSM.h"
#include "inc/lm3s2965.h"

/*****************************************************
 * Module Level Variables
 ****************************************************/
// Module level variable contains the current state
static NestedSMState_t currentState;

/*****************************************************
 * Initialization Function
 ****************************************************/
void InitNestedSM(void)
{
	// All initialization connected to this SM goes here
	currentState = NestedState1;
	interruptFlag = 0;
}

/*****************************************************
 * Run Function
 ****************************************************/
void RunNestedSM(void)
{
	switch(currentState)
	{
		case NestedState1:
			currentState = NestedState2;
		break;
		case NestedState2:
		{
			int i;

			for(i = 0; i < 10000; i++);

			// Turn off LED1
			GPIO_PORTG_DATA_R &= ~0x04;

			// Check for events with if-statements within the SM
			if(1) {
				// Action associated with event
				currentState = NestedState3;
			}
		}
		break;
		case NestedState3:
		{
			// Check interrupt flag for event
			if(interruptFlag == 1) {
				// Action associated with event
				currentState = NestedState2;
			}
		}
	}
}

